import unittest
from api.ihrm_emp_crud_api import IhrmEmpCRUDApi
from api.ihrm_login_api import IhrmLoginApi
from uilts.common_asserts import comm_asserts
from uilts.db_util import DBUtils
from uilts.get_token import get_login_token


class TestEmpCRUD(unittest.TestCase):
    token = None

    @classmethod
    def setUpClass(cls):
        if cls.token is None:
            cls.token = get_login_token()

    @classmethod
    def tearDownClass(cls):
        if cls.token is not None:
            cls.token = None


    def test_add_emp(self):
        emp_data = {
            "username": "mary",
            "mobile": "18453600022",
            "workNumber": "19996633"
        }
        resp = IhrmEmpCRUDApi.add_emp(self.token, emp_data)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_query_emp(self):
        resp = IhrmEmpCRUDApi.query_emp("1911129768863444992", self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_modify_emp(self):
        emp_data = {"username": "jackie"}
        resp = IhrmEmpCRUDApi.modify_emp("1911129768863444992", self.token, emp_data)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_delete_emp(self):
        resp = IhrmEmpCRUDApi.delete_emp("1911129768863444992", self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")
